package xujiwen.transport.servlet;

import xujiwen.transport.bean.ICCard;
import xujiwen.transport.Mgr.ICCardMgr;

import java.text.SimpleDateFormat;
import java.util.Date;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import xujiwen.transport.util.locker.Password;

/**
 * Servlet implementation class for Servlet: Register
 * 
 */
public class AddCard extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {
	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public AddCard() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	@Override
	protected void doGet(final HttpServletRequest request,
			final HttpServletResponse response) throws ServletException,
			IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 *      HttpServletResponse response)
	 */
	@Override
	protected void doPost(final HttpServletRequest request,final HttpServletResponse response) throws ServletException,IOException {
		ICCardMgr im = new ICCardMgr();
		// 指明编码
		request.setCharacterEncoding("utf-8"); 
		
		//System.out.println(password + "\t" + email + "\t");
		try {
			final String icid = request.getParameter("icid");
			final String cid = request.getParameter("cid");
			
			final Double remasum = Double.parseDouble(request.getParameter("remasum"));
			final int year = Integer.parseInt(request.getParameter("year"));
			
			
			final ICCard card = new ICCard();
		
			card.setIcid(icid);
			card.setCid(cid);
			card.setRemaSum(remasum);
			
			im.Save(card, year);
			System.out.println("发售IC卡成功");
		} catch(final NumberFormatException nfex){
			//response.sendRedirect("err.jsp");
			System.out.println("提交错误");			
			return ;
		}
		response.sendRedirect("operate/ICCardMgr.jsp?searchStr=");
	}
}